package com.zbf.order.config;

import com.alibaba.fastjson.JSON;
import com.zbf.order.mapper.TestOrderMapper;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.Map;

/**
 * @author: LCG
 * 作者: LCG
 * 日期: 2021/3/12  14:54
 * 描述:
 */
@Component
public class MyMsgReturnCallBack implements RabbitTemplate.ReturnCallback {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @PostConstruct
    public void init0(){
        rabbitTemplate.setReturnCallback(this);
    }

    @Autowired
    private TestOrderMapper testOrderMapper;

    @Override
    public void returnedMessage(Message message, int i, String s, String s1, String s2) {

        // NO-ROUTE

        System.out.println("==========returnedMessage===============");

        String s3 = new String(message.getBody());
        Map<String,Object> map = JSON.parseObject(s3, Map.class);
        //发送失败
        map.put("state",4);
        testOrderMapper.updateOrder(map);

    }
}
